package com.feicheng.controller.shop.wx.app.client;
import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.GetMapping;


import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.constant.Constant.ENTITY.DEPOSIT_BACK_REQUEST;
import com.feicheng.common.exception.SystemException;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.controller.shop.admin.store.NewAccessController;
import com.feicheng.persistence.entity.DepositBackRequest;
import com.feicheng.common.result.ResultInfo;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.controller.BaseController;
import com.feicheng.persistence.entity.DepositBackRequest;
import com.feicheng.persistence.entity.DepositTransferBatch;
import com.feicheng.persistence.entity.User;


import com.feicheng.service.IFClientService;


import com.feicheng.service.IFPayBackService;

import lombok.extern.slf4j.Slf4j;

@RestController("/wx/app/client/payback")
@RequestMapping("/wx/app/client/payback")
@Slf4j
public class PaybackController extends BaseController{
	@Autowired
	IFPayBackService fPayBackService;
	
//	/**
//	 * 批次单体查询
//	 * @param id
//	 * @return
//	 */
//	
//	@GetMapping("/getDetail")
//	public ResultInfo getDepositTransferDetail(Integer id) {
//		return fPayBackService.getDepositTransferDetail(id);
//	}
//    
//	@GetMapping("/all")
//	public ResultInfo payBackAll(Integer storeId) {
//		
//		return fPayBackService.payBackAll(storeId);
//	}
 
	/**
	 * 新增押金退款记录
	 * @param 
	 * @param 
	 * @return
	 */
	@PostMapping("/info")
	public ResultInfo depositBackRequest(DepositBackRequest depositBackRequest) {
		JSONObject current = getCurrentToken().getToken().getJSONObject(Constant.RESULT.CURRENT);
		User currentUser = current.getObject(Constant.ENTITY.USER.TABLE, User.class);
		depositBackRequest.setUu(currentUser.getUserId());
		return fPayBackService.depositBackRequest(depositBackRequest);
	}
	/**
	 * 押金退款记录分页全查询
	 * @param 
	 * @param 
	 * @return
	 */
	@GetMapping("/page")
	public ResultInfo page(@RequestParam(defaultValue = "1")Integer current,
			               @RequestParam(defaultValue = "10") Integer size,
			               DepositBackRequest depositBackRequest) {
		return ResultInfo.success(fPayBackService.page(current, size, depositBackRequest));
		
	}
	/**
	 * 押金退款记录改状态
	 * @param 
	 * @param 
	 * @return
	 */
	@PutMapping("/info")
	public ResultInfo putDepositBackRequest(List<DepositBackRequest> depositBackRequest) {
		JSONObject current = getCurrentToken().getToken().getJSONObject(Constant.RESULT.CURRENT);
		User currentUser = current.getObject(Constant.ENTITY.USER.TABLE, User.class);
		for (int i = 0; i < depositBackRequest.size(); i++) {
			depositBackRequest.get(i).setUu(currentUser.getUserId());
		}
		return fPayBackService.putDepositBackRequest(depositBackRequest);
	}
	/**
	 * 删除押金退款记录
	 * @param 
	 * @param 
	 * @return
	 */
	@DeleteMapping("/info")
	public ResultInfo deDepositBackRequest(Integer backId) {
		
		return fPayBackService. deDepositBackRequest(backId);
		
	}

    
//	
//	/**
//	 * 批次新增
//	 * @param depositTransferBatch
//	 * @param backIds
//	 * @return
//	 */
//	@PostMapping("/deposit-transfer-batch/info")
//	public ResultInfo depositTransferBatchPost(String depositTransferBatch) {
//		DepositTransferBatch parseObject = JSONObject.parseObject(depositTransferBatch, DepositTransferBatch.class);
//		JSONObject current = getCurrentToken().getToken().getJSONObject(Constant.RESULT.CURRENT);
//		User currentUser = current.getObject(Constant.ENTITY.USER.TABLE, User.class);
//		parseObject.setCu(currentUser.getUserId());
//		
//		return fPayBackService.depositTransferBatchPost(parseObject);
//	}
//
//
//	/**
//	 * 押金返还修改
//	 * @param depositBackRequest
//	 * @return
//	 */
//	@PutMapping("/info")
//    public ResultInfo updateRequestStatu(DepositBackRequest depositBackRequest) {
//		//从token中调取用户
//		JSONObject current = getCurrentToken().getToken().getJSONObject(Constant.RESULT.CURRENT);
//		User currentUser = current.getObject(Constant.ENTITY.USER.TABLE, User.class);
//		//存入当前修改用户
//		depositBackRequest.setUu(currentUser.getUserId());
//		
//		return fPayBackService.updateRequestStatu(depositBackRequest);
//    }
//	/**
//	 * 批次分页查询
//	 * @param current
//	 * @param size
//	 * @param clientId
//	 * @return
//	 */
//	@GetMapping("/page")
//	public ResultInfo page(
//			@RequestParam(defaultValue = "1") Integer current,
//            @RequestParam(defaultValue = "10") Integer size,
//            Integer clientId
//            ){
//		return ResultInfo.success(fPayBackService.page(current, size, clientId));
//	}

}
